package com.ruoyi.iptv.live.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iptv.live.domain.IptvLive;
import com.ruoyi.iptv.live.service.IIptvLiveService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 直播页面Controller
 * 
 * @author 玉念聿辉
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/live/live")
public class IptvLiveController extends BaseController
{
    private String prefix = "live/live";

    @Autowired
    private IIptvLiveService iptvLiveService;

    @RequiresPermissions("live:live:view")
    @GetMapping()
    public String live()
    {
        return prefix + "/live";
    }

    /**
     * 查询直播页面列表
     */
    @RequiresPermissions("live:live:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IptvLive iptvLive)
    {
        startPage();
        List<IptvLive> list = iptvLiveService.selectIptvLiveList(iptvLive);
        return getDataTable(list);
    }

    /**
     * 导出直播页面列表
     */
    @RequiresPermissions("live:live:export")
    @Log(title = "直播页面", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IptvLive iptvLive)
    {
        List<IptvLive> list = iptvLiveService.selectIptvLiveList(iptvLive);
        ExcelUtil<IptvLive> util = new ExcelUtil<IptvLive>(IptvLive.class);
        return util.exportExcel(list, "直播页面数据");
    }

    /**
     * 新增直播页面
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存直播页面
     */
    @RequiresPermissions("live:live:add")
    @Log(title = "直播页面", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IptvLive iptvLive)
    {
        return toAjax(iptvLiveService.insertIptvLive(iptvLive));
    }

    /**
     * 修改直播页面
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IptvLive iptvLive = iptvLiveService.selectIptvLiveById(id);
        mmap.put("iptvLive", iptvLive);
        return prefix + "/edit";
    }

    /**
     * 修改保存直播页面
     */
    @RequiresPermissions("live:live:edit")
    @Log(title = "直播页面", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IptvLive iptvLive)
    {
        return toAjax(iptvLiveService.updateIptvLive(iptvLive));
    }

    /**
     * 删除直播页面
     */
    @RequiresPermissions("live:live:remove")
    @Log(title = "直播页面", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iptvLiveService.deleteIptvLiveByIds(ids));
    }
}
